package org.example.library.service;

import org.apache.ibatis.annotations.Param;
import org.example.library.enmus.BookStatus;
import org.example.library.mapper.BookInfoMapper;
import org.example.library.model.BookInfo;
import org.example.library.model.PageRequest;
import org.example.library.model.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class BookService {
    @Autowired
    private BookInfoMapper bookInfoMapper;
    public PageResult<BookInfo> getBookListByPage(PageRequest pageRequest) {
        Integer count = bookInfoMapper.count();
        List<BookInfo> books = bookInfoMapper.queryBookListByPage(pageRequest);
        for (BookInfo book:books){
            book.setStatusCN(BookStatus.getNameByCode(book.getStatus()).getName());
        }
        return new PageResult<>(count,pageRequest, books);
    }
    public BookInfo queryBookById(Integer bookId) {
        return bookInfoMapper.queryBookById(bookId);
    }
    public void updateBook(BookInfo bookInfo) {

        bookInfoMapper.updateBook(bookInfo);
    }

    public void addBook(BookInfo bookInfo) {

        bookInfoMapper.insertBook(bookInfo);
    }
    public void batchDeleteBook(List<Integer> ids) {

        bookInfoMapper.batchDeleteBook(ids);
    }
}
